<?php
require_once 'nrg/string.ext.js';
require_once 'nrg/uiw/element.class.js';
?>


var Nrg_Uiw_Img = new Class({
	
	Extends: Nrg_Uiw_Element,
	
	src: '',
	
	alt: '',
	
	//--------------------------------------------------------------------------
	//--------------------------------------------------------------------------
	
	initialize: function(options)
	{
		this.parent(options);
		
		this.setAlt( this.getLabel() );
		
		if ( this.options.src ) {
			this.setSrc( this.options.src );
		}
		
		if ( this.options.alt ) {
			this.setAlt( this.options.alt );
		}
	},
	
	//--------------------------------------------------------------------------
	
	/**
	 * Sets the src of the image.
	 * @return Nrg_Ui_Img
	 */
	setSrc: function(src)
	{
		this.src = new String(src);
		return this;
	},
	
	//--------------------------------------------------------------------------
	
	/**
	 * Gets the src of the image.
	 * @return String
	 */
	getSrc: function()
	{
		return this.src;
	},
	
	//--------------------------------------------------------------------------
	
	/**
	 * Sets the alt text of the image.
	 * @return Nrg_Ui_Img
	 */
	setAlt: function(text)
	{
		this.alt = String.from(text);
		return this;
	},
	
	//--------------------------------------------------------------------------
	
	/**
	 * Returns the alt text.
	 * @return String
	 */
	getAlt: function()
	{
		return this.alt;
	},
	
	//--------------------------------------------------------------------------
	
	toString: function()
	{
		return '<img src="'
			+ this.getSrc()
			+ '" alt="'
			+ this.getAlt().valueSafe()
			+ '" title="'
			+ this.getLabel().valueSafe()
			+ '" />';
	}

	//--------------------------------------------------------------------------
	
});